﻿using System.Linq;
using Enyim.Caching;
using Ayatta.Contract;
using System.Web.Mvc;
using Web.Game.Models;
using Ayatta.Contract.Domain;

namespace Web.Game.Controllers
{
    public class GameController : GameBaseController
    {
        public GameController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient)
            : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public ActionResult Index(string param)
        {
            var model = new GameControllerModel();
            var game = GetGames().FirstOrDefault(o => o.SiteName == param);
            if (game != null)
            {
                model.Game = game;
                return View(game.SiteName, "Index", model);
            }
            return Redirect("/");
        }

        public ActionResult Articles(string param, GameArticleCategory category = 0)
        {
            var model = new GameControllerModel();
            var game = GetGames().FirstOrDefault(o => o.SiteName == param);
            if (game != null)
            {
                model.Game = game;
                return View(game.SiteName, "Articles", model);
            }
            return Redirect("/");
        }

        public ActionResult Article(string param, int id = 0)
        {
            var model = new GameControllerModel();
            var game = GetGames().FirstOrDefault(o => o.SiteName == param);
            if (game != null)
            {
                model.Game = game;
                return View(game.SiteName, "Article", model);
            }
            return Redirect("/");
        }


        private new ActionResult View(string site, string view, object model)
        {
            var viewName = string.Format("~/Games/{0}/{1}.cshtml", site, view);
            return View(viewName, model);
        }
    }
}
